import React, { Component } from 'react';
import {ajax,base,getMultiLang } from 'nc-lightapp-front';
const { NCButton: Button, NCTable:Table, NCModal:Modal, NCDiv
    } = base;
const emptyCell = <span>&nbsp;</span>
export default class TransResultModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            showModal: false,
            pk_accountingbook:{
                display:'',
                value:''
            },
            tabelData:[],
            json: {}
        };
    }
    handleCancel = () => {
        let {handleCancel} = this.props
        this.props.modal.close('transresult'); //关闭弹框
        handleCancel && handleCancel()
    }
    show = () => {
        this.props.modal.show('transresult');
    }
    close = () => {
        this.props.modal.close('transresult');
    }
    componentWillMount() {
		let callback= (json) =>{
			this.setState({
				json:json,
			})
		}
		getMultiLang({moduleId:'20020SDTREPAGE',domainName:'gl',currentLocale:'simpchn',callback});
    }
    
    componentWillReceiveProps(nextProps){
        let showModal = nextProps.resultModalShow;
        let tabelData = nextProps.transResult;
        this.setState({
            showModal,tabelData
        })
    }
    componentDidMount(){
        this.props.TransResultModalRef(this);
    }
    modalContent = () => {
        let {transResult}= this.props
        let batResult = transResult.batResult
        if(batResult && batResult.column){
            let col = batResult.column
            col.map((item,index)=>{
                let fieldid = `item${item.key}`
                item.title = (<div fieldid={fieldid}>{item.title}</div>)
                item.width = 180
                if(item.key!=="0"){
                    item.render = (text, record, index) => {
                        /* 国际化处理： 生成凭证*/
                        if (text!==this.state.json['20020SDTREPAGE-000032']) {			
                            return <div fieldid={fieldid} style={{color: 'red'}}>{text ? text : emptyCell}</div>
                        } else {
                            return <div fieldid={fieldid}>{text ? text : emptyCell}</div>
                        }
                    }
                } else {
                    item.render = (text, record, index) => <div fieldid={fieldid}>{text ? text : emptyCell}</div>
                }              
            })
        }
        return(
            <NCDiv fieldid="transresult" areaCode={NCDiv.config.TableCom}>
                <Table className='resultTable'
                    scroll={{ x: true }}
                    columns={(batResult&&batResult.column) ? batResult.column : []}
                    data={(batResult&&batResult.rows)?batResult.rows:''}
                    onRowClick={this.clickRow}
                />
            </NCDiv>
        )
    }
    render () {
        let { modal } = this.props;
        return (
        <div>
            {modal.createModal('transresult', {
                title: this.state.json['20020SDTREPAGE-000030'], /* 国际化处理： 批量结转结果报告*/
                type:'senior',
                content: this.modalContent(), //弹框内容，可以是字符串或dom
                customBtns:<div><Button fieldid='confirm' onClick={ this.handleCancel} shape="border" >{this.state.json['20020SDTREPAGE-000030']}</Button></div>, //JSX结构，样式需要自己写 关闭
                showCustomBtns: true,//允许自定义footer里的按钮,默认false显示 确定 和 取消 按钮，true是传入自定义的按钮
                closeModalEve: this.handleCancel, //关闭按钮事件回调
            })}
        </div>
        )
    }
}
